package org.example.mapper;

import org.apache.ibatis.annotations.*;
import org.example.entity.DeliveryAddress;
import java.util.List;

public interface IDeliveryAddressMapper {
    // 1. 根据用户编号查询所属送货地址
    @Select("SELECT * FROM delivery_address WHERE user_id = #{userId}")
    List<DeliveryAddress> listDeliveryAddressByUserId(@Param("userId") String userId);

    // 2. 根据送货地址编号查询送货地址
    @Select("SELECT * FROM delivery_address WHERE da_id = #{daId}")
    DeliveryAddress getDeliveryAddressById(@Param("daId") Integer daId);

    // 3. 向送货地址表中添加一条记录
    @Insert("INSERT INTO delivery_address (contact_name, contact_sex, contact_tel, address, user_id) VALUES (#{contactName}, #{contactSex}, #{contactTel}, #{address}, #{userId})")
    int saveDeliveryAddress(DeliveryAddress deliveryAddress);

    // 4. 根据送货地址编号更新送货地址信息
    @Update("UPDATE delivery_address SET contact_name = #{contactName}, contact_sex = #{contactSex}, contact_tel = #{contactTel}, address = #{address}, user_id = #{userId} WHERE da_id = #{daId}")
    int updateDeliveryAddress(DeliveryAddress deliveryAddress);

    // 5. 根据送货地址编号删除一条记录
    @Delete("DELETE FROM delivery_address WHERE da_id = #{daId}")
    int removeDeliveryAddress(@Param("daId") Integer daId);
}